#coding=utf-8

import sys
from debug import logprint
from omp_maxpain import get_all_opurls
from base_crul import get_org_htmlstr,get_all_chain_list,get_all_crash_value,get_mp_price
from local_model import update_expdate_list_status,get_daily_check_mp_need,update_daily_mp


#返回日期列表
def get_expdate_list(symb):
    all_opurls=get_all_opurls(symb)
    
    #print all_opurls 
    expdate_list=[]
    for opurl in all_opurls:
        #print opurl
        expdate_list.append(opurl)
        
    #print expdate_list
    return expdate_list


def get_daily_mp(opurl):
    #t_opurl 只用在all_chains 方法中，其它计算都基于all_chains
    htmlstr=get_org_htmlstr(opurl)
    #short_name=get_short_name(htmlstr)
    all_chains=get_all_chain_list(htmlstr)
    
    #获取mp值
    mp=get_mp_price(all_chains)
    
    return mp

def daily_run():
    #update status to 0 first
    update_expdate_list_status()
    
    #get symb need to check
    check_need=get_daily_check_mp_need()
    #print check_need
    mp_dict={}
    
    for check in check_need:
        sy_exp=check[0]
        opurl=check[1]
        try:
            mp=get_daily_mp(opurl)
            mp_dict[sy_exp]=mp
        except Exception,e:
            logprint(e)
        
    #update daily mp table
    update_daily_mp(mp_dict)
    
    
    
###### for local script####
if __name__ == "__main__":
    daily_run()
    
    